﻿using System;

namespace SimpleCalculator
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Welcome to Simple Calculator!");

            // 输入第一个数字
            Console.Write("Enter the first number: ");
            double num1;
            while (!double.TryParse(Console.ReadLine(), out num1))
            {
                Console.WriteLine("Invalid input. Please enter a valid number:");
            }

            // 输入第二个数字
            Console.Write("Enter the second number: ");
            double num2;
            while (!double.TryParse(Console.ReadLine(), out num2))
            {
                Console.WriteLine("Invalid input. Please enter a valid number:");
            }

            // 输入运算符
            Console.Write("Enter the operator (+, -, *, /): ");
            char op = Console.ReadKey().KeyChar;
            Console.WriteLine(); // 换行

            // 执行计算
            double result = 0;
            switch (op)
            {
                case '+':
                    result = num1 + num2;
                    break;
                case '-':
                    result = num1 - num2;
                    break;
                case '*':
                    result = num1 * num2;
                    break;
                case '/':
                    if (num2 != 0)
                    {
                        result = num1 / num2;
                    }
                    else
                    {
                        Console.WriteLine("Error: Division by zero!");
                        return;
                    }
                    break;
                default:
                    Console.WriteLine("Invalid operator!");
                    return;
            }

            // 打印结果
            Console.WriteLine($"Result: {result}");
        }
    }
}
